import random
import time
from functools import cmp_to_key

class Solution(object):
    def largestNumber(self, nums):
        def compare(a, b):
            if str(a) + str(b) > str(b) + str(a):
                return -1
            elif str(a) + str(b) < str(b) + str(a):
                return 1
            else:
                return 0
        
        nums = sorted(nums, key=cmp_to_key(compare))
        result = ''.join(map(str, nums))
        return result if result[0] != '0' else '0'


def generate_test_data():
    """生成测试数据"""
    test_cases = [
        [10, 2],
        [3, 30, 34, 5, 9],
        [1, 2, 3, 4, 5],
        [0, 0],
        [12, 121],
        [432, 43],
        [0, 0, 0, 0],
        [random.randint(1, 999) for _ in range(5)],
        [random.randint(0, 9) for _ in range(8)],
    ]
    return test_cases


def test_algorithm():
    """测试算法"""
    solution = Solution()
    test_cases = generate_test_data()
    
    print("最大数算法测试")
    print("=" * 30)
    
    for i, nums in enumerate(test_cases, 1):
        start_time = time.time()
        result = solution.largestNumber(nums)
        end_time = time.time()
        
        print(f"测试 {i}: {nums}")
        print(f"结果: {result}")
        print(f"时间: {(end_time - start_time)*1000:.2f} ms\n")


if __name__ == "__main__":
    test_algorithm()
